﻿using System;
using ORS.OrderRobot.Domain;
using ORS.OrderRobot.IOC;

namespace ORS.OrderRobot.Service.Jobs
{
    /// <summary>
    /// 更新订单记录表
    /// </summary>
	public class UpdateOrderJob : IBackgroundJob<UpdateOrderArgs>, IScoped
    {
        private readonly IRepository<AccountOrder, int> _repository;
        public UpdateOrderJob(IRepository<AccountOrder, int> repository)
		{
            _repository = repository;
		}

        public async Task ExecuteAsync(UpdateOrderArgs args)
        {
            var entitys = args.Cart.Select(x => new AccountOrder
            {
                AccountId = args.AccountId,
                BoardingId = args.BoardingId,
                CreateTime = args.CreateTime,
                ProductId = x.product_id,
                OrderNo = args.OrderNo,
            });
            await _repository.InsertManyAsync(entitys);
        }
    }
}

